/*_math.h - This defines auxiliary math functions
 *
 * Copyright(c) 2007 Bert van der Weerd<hypercharge@gmail.com>
 *
 * This is Free Software under BSD licence. Share and enjoy.
 */

#ifndef INCLUDED_MATH_H
#define INCLUDED_MATH_H

#include <cmath>


// GNU C #defines log2, we don't want that
#ifdef __GNUC__
# ifdef log2
#  undef log2
# endif
#endif

namespace iondrive {
namespace math {

	using namespace iondrive;


    // we still need to define M_PI and friends these days?

    const long double m_pi  = 3.14159265358979323846;
    const long double m_ln2 = 0.693147180559945309417;

	//
	// Wrappers to standard math functions for type closure (these
	// get optimized away). They could also be used for faster
	// sin() etc functions by using tables.
	// 
	// Another thing that could be done here is partial template specialization
	// for the std::complex type, so we can have more functionality for
	// the glsl::vec and glsl::mat types.
	// 


	template <class T> inline T abs(const T& x)              { return std::abs(x); }
	template <class T> inline T acos(const T& x)             { return std::acos(x); }
	template <class T> inline T asin(const T& x)             { return std::asin(x); }
	template <class T> inline T atan(const T& x)             { return std::atan(x); }
	template <class T> inline T atan2(const T& x,const T& y) { return std::atan2(x,y); }
	template <class T> inline T ceil(const T& x)             { return std::ceil(x); }
	template <class T> inline T cos(const T& x)              { return std::cos(x); }
	template <class T> inline T exp(const T& x)              { return std::exp(x); }
	template <class T> inline T fabs(const T& x)             { return std::fabs(x); }
	template <class T> inline T floor(const T& x)            { return std::floor(x); }
	template <class T> inline T fmod(const T& x,const T& y)  { return std::fmod(x,y); }
	template <class T> inline T log(const T& x)              { return std::log(x); }
	template <class T> inline T pow(const T& x,const T& y)   { return std::pow(x,y); }
	template <class T> inline T sin(const T& x)              { return std::sin(x); }
	template <class T> inline T sqrt(const T& x)             { return std::sqrt(x); }
	template <class T> inline T tan(const T& x)              { return std::tan(x); }


} // namespace math
} // namespace iondrive

#endif /* INCLUDED_MATH_H */


